package top.spring.study.config;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import top.spring.study.filter.LimitRateRequestFilter;
import top.spring.study.filter.TestFilter2;

@Configuration
public class FilterConfiguration {

    @Bean
    public FilterRegistrationBean registTest1(){
        FilterRegistrationBean registrationBean = new FilterRegistrationBean<>();
        registrationBean.setFilter(new LimitRateRequestFilter());//注册自定义过滤器
        registrationBean.setName("limitRateRequestFilter");//过滤器名称
        registrationBean.addUrlPatterns("/*"); //过滤器路径
        /*List<String> list = new ArrayList<>();
        registrationBean.setUrlPatterns(list);*/
        registrationBean.setOrder(9);//优先级，越低越优先
        return registrationBean;
    }

    @Bean
    public FilterRegistrationBean registTest2(){
        FilterRegistrationBean registrationBean = new FilterRegistrationBean<>();
        registrationBean.setFilter(new TestFilter2());
        registrationBean.setName("testFilter2");
        registrationBean.addUrlPatterns("/test/*");
        /*List<String> list = new ArrayList<>();
        registrationBean.setUrlPatterns(list);*/
        registrationBean.setOrder(6);
        return registrationBean;
    }
}
